<!-- Student_studyCourseList.html -->
<!-- studyCourseList.html -->
<!-- 课程列表 -->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
	<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	<title>课程列表</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" href="../../css/mui.min.css"/>
	<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
	<link rel="stylesheet" href="../../css/base.css"/>
	<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
	<style type="text/css">
		/*公共css*/
		#header {
			height: 44px;
			width: 100%;
			color: white;
			background-color: #28292d;
			display: -webkit-flex;
			display: flex;
			align-items: center;
			/*justify-content: space-between;*/
			y-content: center;
		}
		p {
			margin-bottom: 0;
		}
		.test_cell {
			width: 100px;
		}
		.test_cell_title {
			font-size: 14px;
			height: 20px;
		}
		/*一行显示,多余省略号*/
		.text_ellipsis {
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
		span {
			font-size: 12px;
			/*margin-right: 14px;*/
			/*margin-top: 20px;*/
		}
		/*绿色*/
		.green {
			color: #18b4ed;
			/*color:#f57d3b;*/
		}
		.orange {
			color: #f57d3b;
		}
		.source_fen {
			color: #0782e4;
		}
		.schedule, .schedulesymbol {
			color: #323232;
		}
		.schedulecount {
			color: #e5072f;
		}
		/*
         */
		.p_padding {
			padding-top: 8px;
			padding-bottom: 8px;
		}
		#courseInfo {
			background-color: #48baff;
			overflow: hidden;
			padding: 10px;
		}
		#imageContainer {
			float: left;
			margin: 0;
			width: 40%;
			height: 120px;
			display: -webkit-flex;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: white;
			overflow: hidden;
		}
		#titleContainer {
			float: right;
			width: 60%;
		}
		/*ul {
            margin-left: 10px;
        }*/
		.courseInfoTitle {
			color: white;
			font-size: 14px;
			font-weight: normal;
		}
		#studyBtn {
			width: 60px;
			height: 30px;
			background-color: #188eee;
			border: 1px solid #188eee;
			border-radius: 4px;
			color: white;
			font-size: 14px;
		}
		.tabbar {
			height: 40px;
			line-height: 40px;
			text-align: center;
			border-bottom: 1px solid #e0e0e0;
			background: #fff;
		}
		.tabbar .col {
			font-size: 14px;
		}
		.row {
			display: -webkit-box;
			display: -webkit-flex;
			display: flex;
		}
		.col {
			-webkit-box-flex: 1;
			-webkit-flex: 1;
			flex: 1;
			position: relative;
		}
		.indicator {
			height: 2px;
			width: 100%;
			background: #48baff;
			position: absolute;
			bottom: 0;
		}
		.cell_icon {
			margin-right: 4px;
			max-width: 12px;
		}
		.study_class_text {
			color: #393939;
			text-overflow: ellipsis;
			overflow: hidden;
			white-space: nowrap;
			word-break: keep-all;
			line-height: 1em;
			margin-bottom: 14px;
		}
		.study_class_text_title {
			font-size: 16px;
		}
		.study_class_text_content {
			font-size: 14px;
		}
		.tab_img {
			width: 14px;
			position: absolute;
			top: 18px;
			left: 14px;
		}
		#colImg, #colselectImg {
			width: 20px;
			height: 20px;
		}
		#select, #selected {
			padding-left: 10px;
		}
		/*.noInternetDiv,.noDataDiv{
         margin-top: 144px;
         }*/
		.study_class_content {
			background-color: #ecf1f0;
			/*padding-top: 10px;*/
			padding-bottom: 10px;
			overflow: auto;
		}
		.bottom_line {
			border-top: 1px solid #D9D9D9;
			-webkit-transform-origin: 0 0;
			transform-origin: 0 0;
			-webkit-transform: scaleY(0.5);
			transform: scaleY(0.5);
		}
		.line_number_three {
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 3;
			-webkit-box-orient: vertical;
		}
		#study_class_des_div {
			background-color: #ecf1f0;
		}
		.select_right_span {
			float: right;
		}
		/*.mui-table-view{
            margin-left: 0;
        }*/
		.mui-table-view-cell{
			padding: 10px;
		}
		.mui-table-view-cell>a:not(.mui-btn){
			padding: 10px;
			margin: -10px;
		}
		.mui-table-view-cell>a:not(.mui-btn) img{
			display:block;
			width: 136px;
			max-width: 136px;
			height: 84px;
			background-image: url(../../image/course_placehoder.png);
			background-size: 136px 84px;
		}
		.mui-table-view-cell .top-content{
			height: 40px;
		}
		.mui-table-view-cell .bottom-content{
			height: 44px;
		}
		.mui-table-view-cell>a:not(.mui-btn) .course_title{
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: pre-wrap;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
			font-size: 14px;
			color: #222;
			line-height: 1.2em;
		}
		.mui-table-view-cell>a:not(.mui-btn) .subtitle{
			font-size: 12px;
			color: #999;
			line-height: 13px;
		}
		.subtitle-red{
			color: #e10d20;
			font-size: 12px;
			margin: 0;
		}
		.cell-btn{
			width: 70px;
			height: 26px;
			padding: 0;
			background-color: #18b4ed;
			border-color: #18b4ed;
			color: white;
			float: right;
		}
		.cell-btn:enabled:active{
			background-color: #2db4f8;
			border-color: #2db4f8;
		}
		.cell-btn-disable{
			background-color: #d9d9d9;
			border-color: #d9d9d9;
		}
		.cell-btn-disable:enabled:active{
			background-color: #d9d9d9;
			border-color: #d9d9d9;
		}
		.small-title{
			font-size: 12px;
		}
		.top-p{
			margin-top: 10px;
		}
		.bottom-p{
			margin-top: 8px;
		}
		/*.mui-table-view:before{
            top: 0;
        }*/
		.course-status-tag{
			position: absolute;
			bottom: 10px;
			left: 10px;
			font-size: 12px;
			color: white;
			padding: 2px 4px;
			line-height: 1em;
			width: 136px;
			background-color: rgba(0,0,0,0.5);
			text-align: center;
		}
		.course-status-tag-red{
			background-color: #EC1A2B;
		}
		.course-status-tag-green{
			background-color: #1DBF53;
		}
		.right-content{
			width: 80px;
			float: right;
			padding-top: 18px;
		}
		.left-content{
			margin-right: 80px;
		}
		.mui-table-view .mui-media-object.mui-pull-left{
			margin-right: 13px;
		}
		.right-span{
			margin-left: 20px;
		}
		.plan-name-title{
			font-size: 14px;
			color: #222;
			line-height: 14px;
			height: 14px;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical;
		}
		.top-blank-div{
			height: 8px;
			padding: 4px;
			background-color: #f3f5f7;
		}
	</style>
</head>
<body>
<div id="main">
	<ul id="course_list" class="mui-table-view">
		<!-- <li class="mui-table-view-cell top-blank-div"></li>
        <li class="mui-table-view-cell">
            <p class="plan-name-title">
                计划一
            </p>
        </li>
        <li class="mui-table-view-cell mui-media">
            <a href="javascript:;">
                <p class="course-status-tag">已结束</p>
                <img class="mui-media-object mui-pull-left" src="../../image/list-default.png">
                <div class="mui-media-body top-content">
                    <p class="course_title">MOOC课程家职业资格高级物流师培训班的通知</p>
                </div>
                <div class="mui-media-body bottom-content">
                    <div class="right-content">
                        <button type="button" class="mui-btn cell-btn">
                            进入考试
                        </button>
                    </div>
                    <div class="left-content">
                        <p class="mui-ellipsis subtitle top-p">授课老师：江玄燕</p>
                        <p class='mui-ellipsis subtitle small-title bottom-p'>
                            <span class="left-span">
                                自由课程
                            </span>
                            <span class="right-span">
                                已学习
                                <span class="subtitle-red">2</span>
                                /12
                            </span>
                        </p>
                    </div>
                </div>
            </a>
        </li> -->
	</ul>
	<div class="noSign" hidden="hidden" id="noData">
		<img src="../../image/icon_img.png" width="60%">
		<p class="font16 top_15 base_dark_grey" >
			暂无数据
		</p>
	</div>
	<div class="loadFailure" hidden="hidden" id="noNet">
		<img src="../../image/icon_img01.png" width="60%">
		<p class="" >
			数据加载失败
		</p>
		<p>
			请检查您的网络
		</p>
		<button type="button" class="mui-btn mui-btn-outlined" onclick="refreshData()">
			重新加载
		</button>
	</div>
	<!-- <div class="weui_panel weui_panel_access" style="margin-top: 0;">
        <div class="weui_panel_bd"> -->
	<!-- <a class='weui_media_box weui_media_appmsg'>
    <div class='weui_media_hd test_cell' style='width:100px;'>
    <img class='weui_media_appmsg_thumb' src='' alt=''>
    </div>
    <div class='weui_media_bd'>
    <p class='test_cell_title text_ellipsis'>这是一首简单饿小情歌</p>
    <p class='weui_media_desc p_padding'>
    <span class='orange'>选修课</span>
    <span class='schedule'>进度：<span class='schedulecount'><em id='schedule'>99</em><span class='schedulesymbol'>%</span></span>
    <span class='select_right_span' id='select'>未选</span>
    </span>
    </p>
    <p class='weui_media_desc'>
    <span class='text_ellipsis' id='sourcefen'>
    <span>考核成绩：<span class='course_exam_fen'>100</span>
    &nbsp通过分数：100</span>
    </span>
    </p>
    </div>
    <div >
    <span class='weui_cell_ft' id='select'>未选</span>
    </div>
    </a> -->
	<!-- </div>
</div> -->
</div>
</body>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/databaseOperation.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script>
	// 传入最大值范围 如100、1000、10000
	function randomNumber(num) {
		var num1 = Math.random();
		var num2 = num1 * num;
		var num3 = Math.floor(num2);
		return num3;
	};
	var pageParam;
	var page = 1;
	var row = 6;
	//课程搜索默认参数
	var keyword = '';
	var gid = '0';
	var allCourseArr = new Array();
	var dropRefreshCount = 0;
	var oneWeek = 7 * 24 * 60 * 60 * 1000;
	//下拉刷新更新数据条数
	var uid = '';
	var jid = '';
	var isFirstLoad = true;
	var currentPlanid = '';
	// $api.getStorage('cfnetppuid')
	DBReady = function() {
		prepareData();
		pageParam = api.pageParam;
		//屏幕即将显示首页
		api.addEventListener({
			name: 'viewappear'
		}, function(ret, err) {
			// console.log('旧的jid:'+$api.getStorage('cfnetlanxueoldjid')+'\n当前jid:'+$api.getStorage('cfnetppjxid'));
			if ($api.getStorage('cfnetlanxueoldjid') != undefined && $api.getStorage('cfnetlanxueoldjid') != '') {
				$api.setStorage('cfnetppjxid', $api.getStorage('cfnetlanxueoldjid'));
				$api.setStorage('cfnetlanxueoldjid', '');//置空
			}
		});
		/**更新学习进度*/
		api.addEventListener({
			name : 'refreshCourseSchedule'
		}, function(ret, err) {
			//暂时屏蔽
			var courseid = ret.value.courseid;
			var pid = ret.value.pid;
			refreshMoocSchedule(courseid, pid);
			// var schedule = ret.value.schedule + '%';
			// $('#' + courseid).find('.course_schedule').text(schedule);
		});
		api.addEventListener({
			name : 'studyPassedExamNotifi'
		}, function(ret, err) {
			// alert('课程列表页:'+JSON.stringify(ret));
			if (ret) {
				if (ret.value.isthrough == 1) {
					loadNewData();
				} else {
					var courseid = ret.value.cid;
					//课程id
					var score = ret.value.score;
					//分数
					$('#' + courseid).find('.course_exam_fen').text(score);
				}
			}
		});
		api.addEventListener({
			name : 'courseCategoryGetId'
		}, function(ret, err) {
			gid = ret.value.categoryId;
			loadNewData();
		});
		if (pageParam.courseType == 2) {
			api.addEventListener({
				name : 'searchCourseKeyWord'
			}, function(ret, err) {
				keyword = ret.value.keyword;
				loadNewData();
			});
		}
		//添加移除课程通知
		api.addEventListener({
			name : 'refreshCourseList'
		}, function(ret, err) {
			loadNewData();
		});
		// 完成课程
		api.addEventListener({
			name : 'finishStudy'
		}, function(ret, err) {
			loadNewData();
		});
		//添加切换集团通知
		api.addEventListener({
			name: 'changeJidNotifi'
		}, function(ret, err) {
			prepareData();//刷新集团数据
			loadNewData();
		});
		//自由课程更新进度通知
		api.addEventListener({
			name: 'freeCourseScheduleNofiti'
		}, function(ret, err) {
			if (ret) {
				var value = ret.value;
				var undateCourseid = value.courseid;
				var undatePlanid = value.planid;
				refreshFreeCourse(undateCourseid, undatePlanid);
			}
		});
		loadNewData();
		setRefreshHeader();
		setPullUpRefresh();
//			SendBehaviorTrajectoriesNotifi(0, '课程列表', '006');
	}
	//刷新mooc学习进度
	function refreshMoocSchedule(courseid, pid){
		var param = {
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjxid'),
			pid : pid,
			cid : courseid
		};
		// console.log(url_getMoocSchedule+'\n'+JSON.stringify(param));
		cfnetppPOST(url_getMoocSchedule, param, false, function(data, status){
			if (status == 'success') {
				if (data.code == 200) {
					var schedule = data.data;
					$('#' + courseid).find('.course_schedule').text(schedule);
					api.sendEvent({
						name: 'refreshPeopleMoocScheduleNotifi',
						extra: {
							cid: courseid,
							pid: pid,
							schedule: schedule
						}
					});
				}
			}
		});
	}
	//刷新自由课程进度
	function refreshFreeCourse(courseid, planid){
		var param = {
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjxid'),
			pid : planid,
			cid : courseid
		}
		// console.log(url_freeCourseSchedule+'\n'+JSON.stringify(param));
		cfnetppPOST(url_freeCourseSchedule, param, false, function(data, status){
			// alert(JSON.stringify(data));
			if (status == 'success') {
				if (data.code == 200) {
					var studiedNum = parseInt(numStrWithStr(data.data[0].videosum));
					var allNum = parseInt(numStrWithStr(data.data[0].videosums));
					if (studiedNum > allNum) {
						studiedNum = allNum;
					}
					$('#freeStudied'+courseid).text(studiedNum);
					$('#freeAllChapter'+courseid).text(allNum);
				}
			}
		});
	}
	function prepareData() {
		uid = $api.getStorage('cfnetppuid');
		jid = $api.getStorage('cfnetppjxid');
	}

	function loadNewData() {//请求新数据(下拉刷新)一定是先走网络,如果没网则取本地数据
		page = 1;
		currentPlanid = '';
		loadData();
	}

	function loadMoreData() {//todo
		page++;
		loadData();
	}

	function loadData() {
		var params = {
			uid : uid,
			jid : jid,
			page : page,
			pagerows : row,
			isshowfree : 1
		};
		if (isFirstLoad == true) {
			api.showProgress({
				style : 'default',
				animationType : 'fade',
				title : '加载中...',
				text : '',
				modal : false
			});
			isFirstLoad = false;
		}
		var urlString = url_getCourseList;
		if (api.pageParam.openType == 'train_stu') {//实习课程列表
			urlString = url_trainStuCourseList;
		}
		// console.log(JSON.stringify(params)+'\n'+urlString);
		cfnetppPOST(urlString, params, true, function(data, status){
			api.hideProgress();
			api.refreshHeaderLoadDone();
			if (status == 'success') {
				if (data.code == 200) {
					var courseArr = new Array();
					if (api.pageParam.openType == 'train_stu') {//实习课程列表
						courseArr = data.data;
					}else{
						courseArr = data.data.list;
					}
					if (page == 1) {
						allCourseArr = new Array();
					}
					multiplePicturesCache({
						picArr : courseArr,
						picKey : 'coverimages'
					}, function(imageArr){
						loadSucceed(imageArr);
						if (courseArr == null || courseArr == undefined || courseArr == '') {
							if (page == 1) {
								if (allCourseArr.length == 0) {
									$('.noSign').show();
									$('.loadFailure').hide();
								}
								$('#course_list').html('');
							}
						} else {
							$('.noSign').hide();
							$('.loadFailure').hide();
						}
					});
				}else{
					if (page == 1) {
						$('#course_list').html('');
						$('.noSign').show();
						$('.loadFailure').hide();
					}
				}
			}else{
				api.toast({
					msg : '网络异常，请检查网络',
					duration : 2000,
					location : 'bottom'
				});
				loadFailed();
			}
		});
	}

	function loadSucceed(courseArr) {
		openDB(function(ret, err) {
			if (ret.status) {
				var j = 0;
				var htmlString = "";
				if (courseArr == undefined) {
					return;
				}
				if (courseArr.constructor == Array) {
					dropRefreshCount = courseArr.length;
				}
				var courseData;
				var uid = uid;
				var jid = jid;
				for (var i = 0; i < courseArr.length; i++) {
					var course = courseArr[i];
					courseData = {
						source : course.source, //来源 0:自有课程;1:公共课程
						isCollect : course.isCollect,
						crid : course.crid, //选修必修id
						courseid : course.courseid,
						planid : course.planid,
						cstatus : course.cstatus,
						coursename : course.coursename,
						coverimages : course.coverimages,
						viewcount : course.viewcount,
						commentcount : course.commentcount,
						cjd : course.cjd,
						part : course.part,
						selected : 1,
						uid : uid,
						jid : jid,
						uniquekey : course.courseid + uid,
						haveexam : course.haveexam,
						passmark : course.passmark,
						examscore : course.examscore,
						examid : course.examid,
						coursetype : course.coursetype,
						videosum : course.videosum,
						videosums : course.videosums,
						title : course.title,
						speaker : course.speaker,
						is_score : course.is_score,
						isxueba : course.isxueba,
						channel:course.channel,
						resources_status : course.resources_status
					};
					if (pageParam.courseType == 2) {//搜索课程
						courseData = {
							source : course.source,
							isCollect : course.isCollect,
							courseid : course.id,
							crid : course.crid, //选修必修id
							// planid : course.planid,
							planid : 0,
							cstatus : course.cstatus,
							coursename : course.coursename,
							coverimages : course.coverimages,
							// score : course.score,
							viewcount : course.viewcount,
							commentcount : course.commentcount,
							cjd : course.progress,
							selected : course.selected,
							part : course.part,
							uid : uid,
							jid : jid,
							uniquekey : course.id + uid,
							haveexam : course.haveexam,
							passmark : course.passmark,
							examscore : course.examscore,
							examid : course.examid,
							coursetype : course.coursetype,
							title : course.title,
							speaker : course.speaker
						};
					}
					//插入数据库
					if ((courseData.viewcount != null && courseData.viewcount != 'undefined') || (courseData.commentcount != null && courseData.commentcount != 'undefined')){
						inseartCourseData(courseData, function(nowCourseData) {
							updateCourseData(nowCourseData);
						});
					}
					//刷新列表
					var courseString = stitchingHtmlString(courseData);
					if (currentPlanid != course.planid) {
						currentPlanid = course.planid;
						htmlString += planTitleHtml(course.title, i);
					}
					htmlString = htmlString + courseString;
				}
				var tableDiv = $('#course_list');
				if (page == 1) {
					tableDiv.html(htmlString);
				} else {
					tableDiv.append(htmlString);
				}
				cellAddClick();
			}
		});
	}
	function planTitleHtml(title, index){
		var topDiv = '<li class="mui-table-view-cell top-blank-div"></li>';
		if (index == 0 && page == 1) {
			topDiv = '';
		}
		return topDiv+
				'<li class="mui-table-view-cell">'+
				'<p class="plan-name-title">'+
				title+
				'</p>'+
				'</li>';
	}
	function inseartCourseData(courseData, callBack) {
		insertData('t_study_course', courseData, function(ret, err) {
			if (ret.status) {
			} else {
				callBack(courseData);
			}
		});
	}

	function updateCourseData(courseData) {
		var updateSql = "UPDATE t_study_course SET viewcount=" + courseData.viewcount + ", commentcount=" + courseData.commentcount + ", cjd='" + courseData.cjd + "', selected=" + courseData.selected + " WHERE courseid=" + courseData.courseid + " AND uid=" + uid + ";";
		executeSQL(updateSql, function(ret, err) {
			if (ret.status) {
			} else {
			}
		});
	}

	function loadFailed() {
		openDB(function(ret, err) {
			if (ret.status) {
				var startNum = (page - 1) * row;
				var limitString = " LIMIT " + startNum + ", " + row;
				var sql;
				if (pageParam.courseType == 2) {//搜索课程
					sql = "SELECT * FROM t_study_course WHERE uid = " + uid + " ORDER BY courseid DESC" + limitString + ";";
				} else {
					sql = "SELECT * FROM t_study_course WHERE ctype < 3 and selected = 1 and uid = " + uid + " and jid=" + "'" + jid + "'" + " ORDER BY courseid DESC" + limitString + ";";
				}
				selectSQL(sql, function(ret, err) {
					if (ret.status) {
						var courseDatas = ret.data;
						if (page == 1) {//如果刷新则清空数组
							allCourseArr = new Array();
						}
						var htmlString = "";
						for (var i = 0; i < courseDatas.length; i++) {
							var courseData = courseDatas[i];
							var courseString = stitchingHtmlString(courseData);
							htmlString = htmlString + courseString;
						}
						var tableDiv = $('#course_list');
						if (page == 1) {
							tableDiv.html(htmlString);
						} else {
							tableDiv.append(htmlString);
						}
						if (courseDatas == null || courseDatas == undefined || courseDatas == '') {
							if (courseDatas.constructor == Array) {
								dropRefreshCount = courseDatas.length;
							}
							if (page == 1) {
								if (allCourseArr.length == 0) {
									$('.noSign').hide();
									$('.loadFailure').show();
								}
							}
							return;
						} else {
							if (api.pageParam.courseType == 2) {//如果是搜索设置搜索到总数
								var selectCountSql = "SELECT count(*) FROM t_study_course WHERE uid = " + uid + ";";
								selectSQL(selectCountSql, function(ret, err) {
									if (ret.status == true) {
										api.sendEvent({
											name : 'searchedCourseNotifi',
											extra : {
												searchnum : ret.data[0]['count(*)']
											}
										});
									}
								});
							}
							$('.noSign').hide();
							$('.loadFailure').hide();
						}
						cellAddClick();
					} else {
						if (page == 1) {
							if (allCourseArr.length != 0) {
								$('.noSign').hide();
								$('.loadFailure').show();
							}
						}
					}
				});
			}
		});
	}
	function sendBuriedNotifi(busionessid,pagetype,pagetypeid){
		var userinfo = {
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjxid'),
			uname : $api.getStorage('cfnetppusername'),
		}
		var data = {
			busionessid : busionessid,
			pagetype : pagetype,
			pagetypeid : pagetypeid,
			sourceurl : api.pageParam.sourceurl,
			sourcetitle : api.pageParam.sourcetitle,
			accesspageurl :  window.location.pathname,
			accesspagetitle : document.title,
			userinfo : userinfo
		}
		SendBehaviorTrajectoriesNotifi_Study(data);
	}

	function cellAddClick() {
		$('.exam-btn').unbind('click');
		$('.exam-btn').click(function(){
			if ($(this).hasClass('cell-btn-disable')) {
				return;
			}
			event.stopPropagation();
			var planid = $(this).attr('planid');
			var courseid = $(this).attr('courseid');
			var examid = $(this).attr('examid');
			api.openWin({useWKWebView:true,
				name : 'Student_CourseTestExam',
				url : 'Student_CourseTestExam.html',
				pageParam : {
					appkey : 148745497845,
					match_type : 3,
					exam_id : examid,
					plan_id : planid,
					course_id : courseid,
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
				},
			});
			sendBuriedNotifi(1,'课程列表','006')

		});
		$('.weui_media_appmsg').unbind('click');
		$('.weui_media_appmsg').click(function() {
			var imgurl = $(this).attr('imageUrl');
			var title = $(this).attr('title');
			var planid = $(this).attr('planid');
			var courseid = $(this).attr('courseid');
			var cstatus = $(this).attr('cstatus');
			var selected = $(this).attr('selectedstatus');
			var source = $(this).attr('source');
			var part = $(this).attr('part');
			var crid = $(this).attr('crid');
			var examid = $(this).attr('examid');
			var coursetype = $(this).attr('coursetype');
			var is_score = $(this).attr('is_score');
			var isxueba = $(this).attr('isxueba');
			var pageName = '';
			var pageUrl = '';
			var resources_status = $(this).attr('resources_status');
			if (isxueba == '1') {//学霸赛课程
				if (coursetype == 2108) {//自由课程
					pageName = 'Student_FreeCourseTab';
					pageUrl = 'Student_FreeCourseTab.html';
				} else if (coursetype == 2109) {//慕课
					pageName = 'Teacher_XueBaSaiMoocTag';
					pageUrl = '../Teacher_Teach/Teacher_XueBaSaiMoocTag.html';
				} else {
					api.toast({
						msg: '暂不支持该课程类型'
					});
					return;
				}
			}else{
				if (coursetype == 2108) {//自由课程
					pageName = 'Student_FreeCourseTab';
					pageUrl = 'Student_FreeCourseTab.html';
				} else if (coursetype == 2109) {//慕课
					// pageName = 'studyCourseDetail';
					// pageUrl = 'studyCourseDetail.html';
					pageName = 'Teacher_StudyCourseInfo';
					pageUrl = '../Teacher_Teach/Teacher_StudyCourseInfo.html';
				} else {
					api.toast({
						msg: '暂不支持该课程类型'
					});
					return;
				}
			}
			if (api.pageParam.openType == 'train_stu') {//实习学生学习
				if (coursetype == 2108) {//自由课程
					pageName = 'Student_trainFreeCourseTab';
					pageUrl = 'Student_trainFreeCourseTab.html';
				} else if (coursetype == 2109) {//慕课
					pageName = 'Student_trainCourseMoocTab';
					pageUrl = '../Study/Student_trainCourseMoocTab.html';
				} else {
					api.toast({
						msg: '暂不支持该课程类型'
					});
					return;
				}
				if (resources_status == '2') {//蓝血计划课程
					$api.setStorage('cfnetlanxueoldjid', $api.getStorage('cfnetppjxid'));
					$api.setStorage('cfnetppjxid', '696');
				}
			}
			api.openWin({useWKWebView:true,
				name : pageName,
				url : pageUrl,
				bgColor : '#fff',
				vScrollBarEnabled : false,
				hScrollBarEnabled : false,
				pageParam : {
					imgurl : imgurl,//课程图片
					title : title,//课程名称
					courseType : pageParam.courseType,//1 可无
					planid : planid,//计划id
					courseid : courseid,//课程id
					cstatus : cstatus,//0
					selected : selected,//1
					source : source,//积分 可无
					part : part,//集团id
					crid : crid,//可无
					examid : examid,//考试id
					coursename : title,//课程名称
					userType : 'student',//用户类型
					coverimages : imgurl,//课程图片
					is_score : is_score,//可无
					isxueba : isxueba,//0 是否学霸赛
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
					ifteacherstudy:api.pageParam.ifteacherstudy,//false 是否是老师端学习
					openType : api.pageParam.openType
				}
			});
			sendBuriedNotifi(1,'课程列表','006');
		});
	}
	function courseHtmlString(courseData){
		allCourseArr.push(courseData);
	}
	function stitchingHtmlString(courseData) {//拼接html字符串

		allCourseArr.push(courseData);
		var timeTitleHtml = timeTitleWithEndTime(courseData.etime);
		//添加元素
		var imageUrl = courseData.coverimages;
		//课程封面
		// var patt1 = new RegExp("http://");
		// if (!patt1.test(imageUrl)) {
		// 	imageUrl = 'http://cfnet.org.cn/data/uploads/' + imageUrl;
		// }
		var title = courseData.coursename;
		//课程名
		var cstatus = courseData.cstatus;
//			var isrequired = '选修课';
//			//课程类型
//			if (cstatus == 0) {
//				isrequired = '必修课';
//			}
		var selectPrompt = "";
		var selected = 1;
		var collectImageUrl = '../../image/collection.png';
		var isCollect = courseData.isCollect;
		var sourcefen = "";
		//考核
		if (isCollect == 1) {
			collectImageUrl = '../../image/u134.png';
		} else {
			collectImageUrl = '../../image/collection.png';
		}
		if (pageParam.courseType == 2) {//搜索课程全为选修
			cstatus = courseData.cstatus;
			selected = courseData.selected;
			if (selected == 0) {
				selectPrompt = "<span class='select_right_span' id='select'>未选</span>";
			} else if (selected == 1) {
				selectPrompt = "<span class='select_right_span green' id='select'>已选</span>";
			}
		} else {
			//				selectPrompt = "<img class='weui_media_appmsg_thumb' id='colImg' src='" + collectImageUrl + "' alt=''>";
			selectPrompt = "";
		}
		var schedule = "0";//进度
		var str = courseData.cjd;
		if (str == 'undefined' || str == '' || str == undefined) {
			str = '0';
		}
		if (str.indexOf("%") > 0) {
			var sarr = str.split('%');
			schedule = sarr[0];
			//进度
		} else {
			schedule = courseData.cjd;
			//进度
		}
		var courseScore = courseData.examscore;
		if (courseScore == '' || courseScore == null) {
			courseScore = 0;
		}
		var examBtn = '';
		if (courseData.haveexam == 1) {
			sourcefen = "<span>考核成绩：<span class='course_exam_fen'>" + parseInt(courseScore) + "</span>&nbsp通过分数：" + parseInt(courseData.passmark) + "</span>";
			if (schedule == 100) {//学完
				if (courseScore != 0) {
					examBtn = '<button type="button" class="mui-btn cell-btn">'+courseScore+'</button>';
				}else{
					examBtn = '<button type="button" class="mui-btn cell-btn exam-btn" courseid="' + courseData.courseid + '" planid="' + courseData.planid + '" examid="' + courseData.examid + '">进入考试</button>';
				}
			}else{
				examBtn = '<button type="button" class="mui-btn cell-btn cell-btn-disable">进入考试</button>';
			}
		} else {
			sourcefen = "无考核";
		}
		var comment = courseData.commentcount;
		//评论
		var records = courseData.viewcount;
		//查看记录
		// var source = courseData.part == 1 ? '公路院' : '自有集团';
		// 最新 part==0 （课程所属jid） 公共课程
		var sourceTab = "";
		// if (courseData.part == 1) {
		// 	sourceTab = "<img class='tab_img' src='../../image/logo_tab.png' alt='' >";
		// }
		var ClassCourse = "";
		var coursetypeName = "";
		var courseJinDu = "";
		if (pageParam.courseType == 1) {//已选课程
			if (courseData.coursetype == 2108) {
				ClassCourse = "<span class='orange'>自由课程</span>";
				coursetypeName = "自由课程";
				var videosum = parseInt(numStrWithStr(courseData.videosum));
				var videosums = parseInt(numStrWithStr(courseData.videosums));
				if (videosum > videosums) {
					videosum = videosums;
				}
				courseJinDu = '<p class="mui-ellipsis subtitle small-title bottom-p"><span class="left-span">自由课程</span>s<span class="right-span">已学习<span id="freeStudied'+courseData.courseid+'" class="course_schedule subtitle-red">'+videosum+'</span>/<span id="freeAllChapter'+courseData.courseid+'">'+videosums+'</span></span></p>';
			}else if(courseData.coursetype == 2109){
				if(courseData.channel===""){
					coursetypeName="MOOC课程";
				}else if(courseData.channel==="dual"){
					coursetypeName="双元课程";
				}else if(courseData.channel==="train"){
					coursetypeName="模块化实训";
				}else{
					coursetypeName="简洁课程";
				}
				ClassCourse = "<span class='orange'>慕课</span>" + "<span class='schedule'>进度：<span class='schedulecount'><em class='course_schedule'>" + schedule + "</em><span class='schedulesymbol'>%</span></span></span>";
				// courseJinDu = '<p class="mui-ellipsis subtitle small-title bottom-p"><span class="left-span">MOOC课程</span><span class="right-span">已学习 <span class="course_schedule subtitle-red">'+schedule+'%</span></span></p>';
				courseJinDu = '<p class="mui-ellipsis subtitle small-title bottom-p"><span class="left-span">'+coursetypeName+'</span></p>';
			}else{
				courseJinDu = '<p class="mui-ellipsis subtitle small-title bottom-p">已学习 <span class="course_schedule subtitle-red">'+schedule+'%</span></p>';
			}
			// courseJinDu = '<p class="mui-ellipsis subtitle small-title">'+'已学习'+'<span class="subtitle-red">'+'2'+'</span>'+'/12'+'</p>';
		} else {
			ClassCourse = "<span><img src='../../image/comment_num.png' class='cell_icon'>" + comment + "</span>" + "<span><img src='../../image/browse_num.png' class='cell_icon'>" + records + "</span>";
			// +"<span>进度:" + schedule + "</span>";
		}
		var course = "<a class='weui_media_box weui_media_appmsg' id='" + courseData.courseid + "' courseid='" + courseData.courseid + "' selectedstatus='" + selected + "' cstatus='" + cstatus + "' planid='" + courseData.planid + "' source='" + courseData.source + "' part='" + courseData.part + "' crid='" + courseData.crid + "' examid='" + courseData.examid + "' coursetype='" + courseData.coursetype + "'>" + "<div class='weui_media_hd test_cell' style='width:100px;'>" + sourceTab + "<img class='weui_media_appmsg_thumb' src='" + imageUrl + "' alt=''>" + "</div>" + "<div class='weui_media_bd'>" + "<p class='test_cell_title text_ellipsis base_title_color'>" + title + "</p>" + "<p class='weui_media_desc p_padding'>" + ClassCourse + selectPrompt + "</p>" + "<p class='weui_media_desc'>" + "<span class='text_ellipsis source_fen'>" + sourcefen + "</span>" + "</p>" + "</div>" +
				// "<div >" +
				// 	selectPrompt +
				// "</div>" +
				//							"<div onClick='collectionClick("+courseData.courseid+","+courseData.source+" ,event)'>"+
				//								selectPrompt +
				//							"</div>"
				"</a>";
		// return course;
		return '<li id="' + courseData.courseid + '" is_score="'+courseData.is_score+'" imageUrl="' + imageUrl + '" title="' + title + '" courseid="' + courseData.courseid + '" selectedstatus="' + selected + '" cstatus="' + cstatus + '" planid="' + courseData.planid + '" source="' + courseData.source + '" part="' + courseData.part + '" crid="' + courseData.crid + '" examid="' + courseData.examid + '" isxueba="' + courseData.isxueba + '" coursetype="' + courseData.coursetype + '" resources_status="' + courseData.resources_status + '" class="mui-table-view-cell mui-media weui_media_appmsg">'+
				'<a href="javascript:;">'+
				timeTitleHtml+
				'<img class="mui-media-object mui-pull-left" src="'+imageUrl+'">'+
				'<div class="mui-media-body top-content">'+
				'<p class="course_title">'+
				title+
				'</p>'+
				'</div>'+
				'<div class="mui-media-body bottom-content">'+
				'<div style="float:right">'+

				'</div>'+
				// '<div class="left-content">'+
				'<div class="">'+
				'<p class="mui-ellipsis subtitle top-p">授课老师：'+courseData.speaker+'</p>'+
				courseJinDu+
				'</div>'+
				'</div>'+
				'</a>'+
				'</li>';
	}
	function joinChart(){
		$('.as').hide();
		event.stopPropagation();
		api.openWin({useWKWebView:true,
			name : 'chartGroup',
			url : '../chart/chartGroup.html'

		});
	}
	function numStrWithStr(str){
		if (str == '' || str == null || str == undefined) {
			return '0';
		}
		return str;
	}
	//时间标签
	function timeTitleWithEndTime(endTime){
		var timeTitleHtml = '';
		var etime = parseInt(endTime) * 1000;//结束时间
		var nowTime = Date.parse(new Date());
		// alert("结束时间"+etime+'\n当前时间'+nowTime);
		if (etime <= nowTime) {
			timeTitleHtml = '<p class="course-status-tag">已结束</p>';
		}else{
			var tmpTime = etime - nowTime;
			if (tmpTime <= oneWeek) {
				// var remainingTime = (oneWeek - tmpTime) / (24 * 60 * 60 * 1000);
				// if (remainingTime == 0) {
				// 	timeTitleHtml = '<p class="course-status-tag course-status-tag-red">最后一天</p>';
				// }else{
				var timeDate = new Date(etime);
				var timeMonth = timeDate.getMonth() + 1;
				var timeDay = timeDate.getDate();
				var timeTitle = timeMonth + '-' + timeDay + '到期';
				timeTitleHtml = '<p class="course-status-tag">' + timeTitle + '</p>';
				// }
			}
		}
		return timeTitleHtml;
	}
	function collectiondb(sql) {
		openDB(function(ret, err) {
			executeSQL(sql, function(ret, err) {
			});
		});
	}

	//下拉刷新
	function setRefreshHeader() {
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : '#ccc',
			textColor : '#fff',
			textDown : '下拉刷新...',
			textUp : '松开刷新...',
			showTime : true
		}, function(ret, err) {
			loadNewData();
		});
	}

	// 上拉加载
	function setPullUpRefresh() {
		api.addEventListener({
			name : 'scrolltobottom'
		}, function(ret, err) {
			if (dropRefreshCount >= row) {
				loadMoreData();
			}
		});
	}
	function refreshData(){
		isFirstLoad = true;
		loadNewData();
	}
</script>
</html>